import urllib.request

file = urllib.request.urlopen("http://www.baidu.com")
data = file.read()

dataline = file.readline()

print(data)

print("----------------------\r\n")

print(dataline)


filehandle = open("./data/pr1.html", "wb")
filehandle.write(data)
filehandle.close()

filename = urllib.request.urlretrieve("http://edu.51cto.com", filename="./data/2.html")
urllib.request.urlcleanup()

# file info

print(file.info())
print(file.getcode())
print(file.geturl())

# url

quote_url = urllib.request.quote(file.geturl())
print(quote_url)
unquote_url = urllib.request.unquote(quote_url)
print(unquote_url)

# for http headers

url_csdn = "http://blog.csdn.net/weiwei_pig/article/details/51178226"
file_csdn = urllib.request.urlopen(url_csdn)




